package 算法.leetcode.offer.base;

/**
 * @author lchenglong
 * @date 2022/3/17
 */
public class ListNode {
    public int val;
    public ListNode next;
    public ListNode(int x) { val = x; }

    public static ListNode init(int[] arr){
        if (arr == null || arr.length == 0)return null;
        ListNode head = new ListNode(arr[0]),cur = head;
        for (int i=1;i<arr.length;i++) {
            ListNode node = new ListNode(arr[i]);
            cur.next = node;
            cur = cur.next;
        }
        return head;
    }

    public  static void print(ListNode listNode){
        while (listNode!=null){
            if (listNode.next!=null)
            System.out.print(listNode.val+"-->");
            else
                System.out.println(listNode.val);
            listNode = listNode.next;
        }
    }

}
